﻿using System;
using System.Collections.Generic;

using Web.Library.Enum;
using Web.Library.DomainObject.SQLServer;
using Web.Library.DataAccess.SQLServer;

namespace Web.Library.Facade.SQLServer
{
    public partial class SysGroupAuthorizationFacade
    {
     
        public List<Dictionary<string, Dictionary<string, string>>> RetrieveMenuAuthorizationByGroupIDAndParentID(int GroupID, int ParentID, string ParentTitle, List<Dictionary<string, Dictionary<string, string>>> menuAuthList, bool withChild)
        {
            try
            {
               
                //Collection<Menu> collection1 = new Collection<Menu>();
                List<SysMenu> collection2 = dal.RetrieveMenuAuthorizationByGroupIDAndParentID(GroupID, ParentID);
                if (collection2.Count > 0)
                {
                    string str = string.Empty;
                    foreach (SysMenu menu in collection2)
                    {
                        Dictionary<string, string> dictionary1 = new Dictionary<string, string>();
                        Dictionary<string, Dictionary<string, string>> dictionary2 = new Dictionary<string, Dictionary<string, string>>();
                        string ParentTitle1 = menu.Url.Split(new char[1]
            {
              '/'
            })[0].Replace(".aspx", "");
                        if (!string.IsNullOrEmpty(ParentTitle))
                            ParentTitle1 = ParentTitle + "_" + ParentTitle1;
                        dictionary1.Add("ID", menu.MenuID.ToString());
                        dictionary1.Add("Parent", ParentTitle1);
                        dictionary1.Add("Title", menu.Title);
                        dictionary1.Add("Url", menu.Url);
                        dictionary2.Add("Menu", dictionary1);
                        menuAuthList.Add(dictionary2);
                        if (withChild)
                            this.RetrieveMenuAuthorizationByGroupIDAndParentID(GroupID, menu.MenuID, ParentTitle1, menuAuthList, withChild);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return menuAuthList;
        }

        public SysGroupAuthorization RetrieveAuthorizationByGroupIDAndMenuID(int GroupID, int MenuID)
        {
            //GroupAuthorization groupAuthorization1 = new GroupAuthorization();
            SysGroupAuthorization groupAuthorization2;
            try
            {
                groupAuthorization2 = dal.RetrieveMenuAuthorizationByGroupIDAndMenuID(GroupID, MenuID);// new GroupAuthorizationDAL().RetrieveAuthorizationByGroupIDAndMenuID(GroupID, MenuID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return groupAuthorization2;
        }

        public bool UpdateInsert(SysGroupAuthorization domain)
        {
            return dal.UpdateInsert(domain);
        }
    }
}
